#ifndef __RESERVED_JOBS_H_
#define __RESERVED_JOBS_H_

#include "Data.h"


class ReservedJobs  : public ACE_Task<ACE_MT_SYNCH>
{
public:

	static ReservedJobs gReservedJobs;

	std::vector<ReservedInfo> vecSucceededJobs;
	std::vector<ReservedInfo> vecFailedJobs;
	ACE_Thread_Mutex	jobLock;

	bool stop;


	ReservedJobs()
	{
		stop = false;
	}


	~ReservedJobs()
	{
		stop = true;
		this->wait();
	}

	static void Start();
	static void Stop()
	{
		gReservedJobs.stop = true;
		gReservedJobs.wait();
		printf("RESERVED JOBS END\n");
	}

	static void push(_RESERVED_TYPE reserved_type , const ReservedInfo & info);
	static void push(_RESERVED_TYPE reserved_type , const _JOB_INFO& job_info);
	static void push(_RESERVED_TYPE reserved_type , const _JOB_INFO& job_info , const _WORK_RESULT& result);

	static void move(std::vector<ReservedInfo>& vecSucceeded , std::vector<ReservedInfo>& vecFailed);
	static void cancel(_RESERVED_TYPE reserved_type ,const ReservedInfo& info);

	int svc(void);


};


class JOB_MONITOR : public ACE_Task<ACE_MT_SYNCH> 
{
private:
	static JOB_MONITOR g_Monitor;

	std::vector<std::string> m_vecStartData;
	std::vector<std::string> m_vecEndData;

	bool m_bStop;

	void Insert(const bool start , const std::string& job_id);

public:

	ACE_Thread_Mutex jobLock;	


	JOB_MONITOR()
	{
		m_bStop = false;
	}

	~JOB_MONITOR()
	{
		m_bStop = true;
		this->wait();
	}

	int svc();

public:

	static void Start()
	{
		g_Monitor.activate();
	}

	static void Stop()
	{
		g_Monitor.m_bStop = true;
		g_Monitor.wait();
		printf("JOB MONITOR END\n");
	}

	static void StartJob(_JOB_INFO & job_info);
	static void EndJob(_JOB_INFO & job_info , _WORK_RESULT& result);

	static void move(std::vector<std::string>& vecStart , std::vector<std::string>& vecEnd);
	static void cancel(const bool start ,const std::vector<std::string>& vec);

};


#endif
